import Vue, { createApp } from 'vue'
import App from './App.vue'
import '@/assets/css/global.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import app from "@/App";
import router from "@/router";
import store  from "./store";
import Layui from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import { DatePicker } from 'ant-design-vue';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import VueCookies from 'vue-cookies'
import axios from "axios";
import Cookies from "js-cookie";


createApp(App).use(ElementPlus).use(router).use(store).use(Layui).use(DatePicker).use(Antd).use(require('vue-cookies')).use(VueCookies).mount('#app')
// app.config.globalProperties.$cookies=VueCookies
// axios.defaults.withCredentials=true


// for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
//     app.component(key, component)
// }
router.beforeEach(function(to, from, next) {
    if (to.meta.needLogin) {
        //页面是否登录
        if (Cookies.get('user')!==undefined) {
            //本地存储中是否有token(uid)数据
            next(); //表示已经登录
        } else {
            store.commit("setCode",333)
            //next可以传递一个路由对象作为参数 表示需要跳转到的页面
            next({
                name: "login"
            });
        }
    } else {
        //表示不需要登录
        next(); //继续往后走
    }
});

